package com.hema.auction.widget.view;

import android.content.Context;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.AttributeSet;

import com.hema.auction.R;

/**
 * author by john
 */

public class RefreshLayout extends SwipeRefreshLayout {

    private OnRefreshListener onRefreshListener;

    public RefreshLayout(Context context) {
        super(context);
    }

    public RefreshLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        setColorSchemeResources(R.color.colorPrimary);
    }

    @Override
    public void setOnRefreshListener(OnRefreshListener listener) {
        super.setOnRefreshListener(listener);
        this.onRefreshListener = listener;
    }

    public void setRefresh(boolean refreshing) {
        post(() -> {
            RefreshLayout.this.setRefreshing(refreshing);
            if (onRefreshListener != null && refreshing)
                onRefreshListener.onRefresh();
        });
    }

}
